home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Burning & Media
/
GB-PVR 1.2.13
/
GBPVR10213.msi
/
Cabs.w1.cab
/
SavedSearch.cs500
< prev
next >
Wrap
Text File
|
2007-12-01
|
41KB
|
998 lines
using System;
using System.Collections;
using System.IO;
using System.Text;
using System.Web.UI.WebControls;
using System.Xml;
using GBPVR.Public;
using GBPVRSchedule;
using Microsoft.Win32;
/// <summary>
/// Summary description for SavedSearch
/// </summary>
///
namespace gbweb
{
#region Object used to save and load searches
public class SavedSearch
{
private string searchName;
private bool autoShowSearch;
private bool autoRecordSearch;
private bool searchTitle;
private bool searchSubTitle;
private bool searchDescription;
private string searchPhrase;
private bool searchCaseSensitive;
private ArrayList searchGenres;
private string searchLengthMin;
private string searchLengthMax;
private string searchTreeviewSortOrder;
private ArrayList searchChannels;
private string searchStartDate;
private string searchStartTime;
private string searchEndDate;
private string searchEndTime;
private string searchVersion;
public SavedSearch()
{
///Object used to manipulate saved searches
searchName = string.Empty;
autoShowSearch = false;
autoRecordSearch = false;
searchTitle = true;
searchSubTitle = false;
searchDescription = false;
searchPhrase = string.Empty;
searchCaseSensitive = false;
searchGenres = new ArrayList();
searchLengthMin = string.Empty;
searchLengthMax = string.Empty;
searchTreeviewSortOrder = string.Empty;
searchChannels = new ArrayList();
searchStartDate = null;
searchStartTime = null;
searchEndDate = null;
searchEndTime = null;
searchVersion = null;
}
public SavedSearch(string searchName, bool autoShowSearch, bool autoRecordSearch, bool searchTitle, bool searchSubTitle, bool searchDescription, string searchPhrase, bool searchCaseSensitive,
ArrayList searchGenres, string searchLengthMin, string searchLengthMax, string searchTreeviewSortOrder, ArrayList searchChannels, string searchStartDate,
string searchStartTime, string searchEndDate, string searchEndTime)
{
///Object used to manipulate saved searches
this.searchName = searchName;
this.autoShowSearch = autoShowSearch;
this.autoRecordSearch = autoRecordSearch;
this.searchTitle = searchTitle;
this.searchChannels = searchChannels;
this.searchTreeviewSortOrder = searchTreeviewSortOrder;
this.searchLengthMax = searchLengthMax;
this.searchLengthMin = searchLengthMin;
this.searchGenres = searchGenres;
this.searchPhrase = searchPhrase;
this.searchCaseSensitive = searchCaseSensitive;
this.searchDescription = searchDescription;
this.searchSubTitle = searchSubTitle;
this.searchStartDate = searchStartDate;
this.searchStartTime = searchStartTime;
this.searchEndDate = searchEndDate;
this.searchEndTime = searchEndTime;
searchVersion = "2.0";
}
public string getSearchVersion()
{
return searchVersion;
}
public void setSearchVersion(string a)
{
searchVersion = a;
}
public string getSearchName()
{
return searchName;
}
public void setSearchName(string a)
{
searchName = a;
}
public bool isAutoShowSearch()
{
return autoShowSearch;
}
public void setautoShowSearch(bool a)
{
autoShowSearch = a;
}
public bool isAutoRecordSearch()
{
return autoRecordSearch;
}
public void setautoRecordSearch(bool a)
{
autoRecordSearch = a;
}
public bool getSearchTitle()
{
return searchTitle;
}
public void setSearchTitle(bool a)
{
searchTitle = a;
}
public bool getSearchSubTitle()
{
return searchSubTitle;
}
public void setSearchSubTitle(bool a)
{
searchSubTitle = a;
}
public bool getSearchDescription()
{
return searchDescription;
}
public void setSearchDescription(bool a)
{
searchDescription = a;
}
public string getTreeViewSortOrder()
{
return searchTreeviewSortOrder;
}
public void setTreeviewSortOrder(string a)
{
searchTreeviewSortOrder = a;
}
public string getSearchLengthMin()
{
return searchLengthMin;
}
public void setSearchLengthMin(string a)
{
searchLengthMin = a;
}
public string getSearchLengthMax()
{
return searchLengthMax;
}
public void setSearchLengthMax(string a)
{
searchLengthMax = a;
}
public ArrayList getSearchGenres()
{
return searchGenres;
}
public void setSearchGenres(ArrayList a)
{
searchGenres = a;
}
public void addSearchGenres(string a)
{
searchGenres.Add(a);
}
public string getSearchPhrase()
{
return searchPhrase;
}
public void setSearchPhrase(string a)
{
searchPhrase = a;
}
public bool isCaseSensitiveSearch()
{
return searchCaseSensitive;
}
public void setSearchCaseSensitive(bool a)
{
searchCaseSensitive = a;
}
public ArrayList getSearchChannels()
{
return searchChannels;
}
public void setSearchChannels(ArrayList a)
{
searchChannels = a;
}
public void addSearchChannels(string a)
{
searchChannels.Add(a);
}
public void setSearchStartDate(string a)
{
searchStartDate = a;
}
public string getSearchStartDate()
{
return searchStartDate;
}
public void setSearchStartTime(string a)
{
searchStartTime = a;
}
public string getSearchStartTime()
{
return searchStartTime;
}
public void setSearchEndDate(string a)
{
searchEndDate = a;
}
public string getSearchEndDate()
{
return searchEndDate;
}
public void setSearchEndTime(string a)
{
searchEndTime = a;
}
public string getSearchEndTime()
{
return searchEndTime;
}
}
#endregion
#region Utility Class used to work with the SavedSearch Object
public class SavedSearchUtils
{
public DateTime toDate(string a)
{
DateTime dte = Convert.ToDateTime(a);
return dte;
}
public DropDownList loadSearchList(DropDownList searchNames, string filter)
{
//Method to load saved search titles to a dropdown list
XmlDocument xmlDoc = new XmlDocument();
XmlNode node;
if (File.Exists(GetWebConfigFileName()))
{
try
{
xmlDoc.Load(GetWebConfigFileName());
//Load initial line of the dropdownlist
searchNames.Items.Add("Choose Saved Search...");
XmlNodeList searches = xmlDoc.GetElementsByTagName("SearchName");
//Create an array to hold all the search names
ArrayList srchNames = new ArrayList();
//Load the found search names to the array applying the appropriate filter
foreach (XmlNode name in searches )
{
if (filter != "all")
{
bool auto = false;
bool auto_record = false;
node =
xmlDoc.DocumentElement.SelectSingleNode("Search[@id='" + name.InnerText +
"']/SearchName");
//Set the auto-search flag from the saved search
try
{
auto = (Convert.ToBoolean(node.Attributes["autoShowSearch"].InnerText));
}
catch
{
auto = false;
}
//Set the auto-record flag from the saved search
try
{
auto_record = (Convert.ToBoolean(node.Attributes["autoRecordSearch"].InnerText));
}
catch
{
auto_record = false;
}
if (filter == "auto" && auto)
{
srchNames.Add(name.InnerText);
}
else if (filter == "auto-record" && auto_record)
{
srchNames.Add(name.InnerText);
}
else if (filter == "auto-all" && (auto_record || auto))
{
srchNames.Add(name.InnerText);
}
else if (filter == "non-auto" && !auto && !auto_record)
{
srchNames.Add(name.InnerText);
}
}
else
{
srchNames.Add(name.InnerText);
}
}
//Sort the array of search names
srchNames.Sort();
//Load the sorted array of search names to the dropdownlist
foreach (string srchname in srchNames)
{
searchNames.Items.Add(srchname);
}
}
catch
{
searchNames.Items.Add("Choose Saved Search...");
}
}
else
{
//if file is not found, create a new xml file
XmlTextWriter xmlWriter = new XmlTextWriter(GetWebConfigFileName(), Encoding.UTF8);
xmlWriter.Formatting = Formatting.Indented;
xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
xmlWriter.WriteStartElement("SavedWebSearches");
xmlWriter.Close();
xmlDoc.Load(GetWebConfigFileName());
searchNames.Items.Add("Choose Saved Search...");
}
return searchNames;
}
public ArrayList loadAutoSearches()
{
//Method to load saved search information into a SavedSearch object
ArrayList searchArray = new ArrayList();
if (File.Exists(GetWebConfigFileName()))
{
try
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(GetWebConfigFileName());
XmlNode node;
XmlNodeList searchlist;
string yes = "True";
searchlist = xmlDoc.DocumentElement.SelectNodes("Search/SearchName[@autoShowSearch='" + yes + "']");
foreach (XmlNode searchName in searchlist)
{
SavedSearch search = new SavedSearch();
search = loadSearch(searchName.InnerText);
searchArray.Add(search);
}
searchlist = xmlDoc.DocumentElement.SelectNodes("Search/SearchName[@autoRecordSearch='" + yes + "']");
foreach (XmlNode searchName in searchlist)
{
SavedSearch search = new SavedSearch();
search = loadSearch(searchName.InnerText);
searchArray.Add(search);
}
}
catch
{
}
}
searchArray.TrimToSize();
return searchArray;
}
public SavedSearch loadSearch(string searchName)
{
//Method to load saved search information into a SavedSearch object
SavedSearch search = new SavedSearch();
if (File.Exists(GetWebConfigFileName()))
{
try
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(GetWebConfigFileName());
search.setSearchName(searchName);
XmlNode node;
XmlNodeList nodelist;
node = xmlDoc.DocumentElement.SelectSingleNode("Search[@id='" + searchName + "']/SearchName");
try
{
search.setautoShowSearch(Convert.ToBoolean(node.Attributes["autoShowSearch"].InnerText));
}
catch
{
}
try
{
search.setautoRecordSearch(Convert.ToBoolean(node.Attributes["autoRecordSearch"].InnerText));
}
catch
{
}
try
{
search.setSearchCaseSensitive(Convert.ToBoolean(node.Attributes["caseSensitiveSearch"].InnerText));
}
catch
{
}
node = xmlDoc.DocumentElement.SelectSingleNode("Search[@id='" + searchName + "']/SearchVersion");
if (node != null)
{
search.setSearchVersion(node.InnerText);
}
else
{
search.setSearchVersion(null);
}
node = xmlDoc.DocumentElement.SelectSingleNode("Search[@id='" + searchName + "']/SearchTitle");
search.setSearchTitle(Convert.ToBoolean(node.InnerText));
node = xmlDoc.DocumentElement.SelectSingleNode("Search[@id='" + searchName + "']/SearchDescription");
search.setSearchDescription(Convert.ToBoolean(node.InnerText));
node = xmlDoc.DocumentElement.SelectSingleNode("Search[@id='" + searchName + "']/SearchSubTitle");
search.setSearchSubTitle(Convert.ToBoolean(node.InnerText));
node = xmlDoc.DocumentElement.SelectSingleNode("Search[@id='" + searchName + "']/SearchPhrase");
search.setSearchPhrase(node.InnerText);
nodelist = xmlDoc.DocumentElement.SelectNodes("Search[@id='" + searchName + "']//SearchGenre/Genre");
foreach (XmlNode genre in nodelist)
{
search.addSearchGenres(genre.InnerText);
}
node = xmlDoc.DocumentElement.SelectSingleNode("Search[@id='" + searchName + "']/SearchLengthMin");
search.setSearchLengthMin(node.InnerText);
node = xmlDoc.DocumentElement.SelectSingleNode("Search[@id='" + searchName + "']/SearchLengthMax");
search.setSearchLengthMax(node.InnerText);
node = xmlDoc.DocumentElement.SelectSingleNode("Search[@id='" + searchName + "']/TreeviewSearchOrder");
search.setTreeviewSortOrder(node.InnerText);
nodelist = xmlDoc.DocumentElement.SelectNodes("Search[@id='" + searchName + "']//SearchChannels/Channel");
foreach (XmlNode channel in nodelist)
{
search.addSearchChannels(channel.InnerText);
}
//Load the start and end dates and times if they were entered for the search.
try
{
node =
xmlDoc.DocumentElement.SelectSingleNode("Search[@id='" + searchName + "']/SearchStartDate");
search.setSearchStartDate(node.InnerText);
}
catch(Exception x)
{
}
try
{
node =
xmlDoc.DocumentElement.SelectSingleNode("Search[@id='" + searchName + "']/SearchStartTime");
search.setSearchStartTime(node.InnerText);
}
catch (Exception x)
{
}
try
{
node =
xmlDoc.DocumentElement.SelectSingleNode("Search[@id='" + searchName + "']/SearchEndDate");
search.setSearchEndDate(node.InnerText);
}
catch (Exception x)
{
}
try
{
node =
xmlDoc.DocumentElement.SelectSingleNode("Search[@id='" + searchName + "']/SearchEndTime");
search.setSearchEndTime(node.InnerText);
}
catch (Exception x)
{
}
}
catch
{
}
}
return search;
}
public void deleteSearch(string searchName)
{
//Method to remove saved search from the saved search XML file
XmlDocument xmlDoc = new XmlDocument();
if (File.Exists(GetWebConfigFileName()))
{
xmlDoc.Load(GetWebConfigFileName());
XmlNode node = xmlDoc.SelectSingleNode("descendant::Search[@id='" + searchName + "']");
if (node != null)
{
xmlDoc.DocumentElement.RemoveChild(node);
xmlDoc.Save(GetWebConfigFileName());
}
}
}
public void writeSearch(SavedSearch search)
{
//Method to write a SavedSearch object to the saved search XML file
try
{
XmlDocument xmlDoc = new XmlDocument();
if (File.Exists(GetWebConfigFileName()))
{
xmlDoc.Load(GetWebConfigFileName());
}
else
{
//if file is not found, create a new xml file
XmlTextWriter xmlWriter = new XmlTextWriter(GetWebConfigFileName(), Encoding.UTF8);
xmlWriter.Formatting = Formatting.Indented;
xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
xmlWriter.WriteStartElement("SavedWebSearches");
xmlWriter.Close();
xmlDoc.Load(GetWebConfigFileName());
}
XmlNode root = xmlDoc.DocumentElement;
XmlElement node1 = xmlDoc.CreateElement("Search");
node1.SetAttribute("id", search.getSearchName());
root.AppendChild(node1);
XmlElement node2a = xmlDoc.CreateElement("SearchVersion");
XmlText node2aText = xmlDoc.CreateTextNode(search.getSearchVersion());
node1.AppendChild(node2a);
node2a.AppendChild(node2aText);
XmlElement node2 = xmlDoc.CreateElement("SearchName");
XmlText node2Text = xmlDoc.CreateTextNode(search.getSearchName());
node2.SetAttribute("autoShowSearch", Convert.ToString(search.isAutoShowSearch()));
node2.SetAttribute("autoRecordSearch", Convert.ToString(search.isAutoRecordSearch()));
node2.SetAttribute("caseSensitiveSearch", Convert.ToString(search.isCaseSensitiveSearch()));
node1.AppendChild(node2);
node2.AppendChild(node2Text);
XmlElement node3 = xmlDoc.CreateElement("SearchTitle");
XmlText node3Text = xmlDoc.CreateTextNode(search.getSearchTitle().ToString());
node1.AppendChild(node3);
node3.AppendChild(node3Text);
XmlElement node4 = xmlDoc.CreateElement("SearchSubTitle");
XmlText node4Text = xmlDoc.CreateTextNode(search.getSearchSubTitle().ToString());
node1.AppendChild(node4);
node4.AppendChild(node4Text);
XmlElement node5 = xmlDoc.CreateElement("SearchDescription");
XmlText node5Text = xmlDoc.CreateTextNode(search.getSearchDescription().ToString());
node1.AppendChild(node5);
node5.AppendChild(node5Text);
XmlElement node6 = xmlDoc.CreateElement("SearchPhrase");
XmlText node6Text = xmlDoc.CreateTextNode(search.getSearchPhrase());
node1.AppendChild(node6);
node6.AppendChild(node6Text);
XmlElement node7 = xmlDoc.CreateElement("SearchGenre");
node1.AppendChild(node7);
foreach(string genre in search.getSearchGenres())
{
XmlElement node7a = xmlDoc.CreateElement("Genre");
XmlText node7aText = xmlDoc.CreateTextNode(genre);
node7.AppendChild(node7a);
node7a.AppendChild(node7aText);
}
XmlElement node8 = xmlDoc.CreateElement("SearchLengthMin");
XmlText node8Text = xmlDoc.CreateTextNode(search.getSearchLengthMin());
node1.AppendChild(node8);
node8.AppendChild(node8Text);
XmlElement node9 = xmlDoc.CreateElement("SearchLengthMax");
XmlText node9Text = xmlDoc.CreateTextNode(search.getSearchLengthMax());
node1.AppendChild(node9);
node9.AppendChild(node9Text);
XmlElement node10 = xmlDoc.CreateElement("TreeviewSearchOrder");
XmlText node10Text = xmlDoc.CreateTextNode(search.getTreeViewSortOrder());
node1.AppendChild(node10);
node10.AppendChild(node10Text);
XmlElement node11 = xmlDoc.CreateElement("SearchChannels");
node1.AppendChild(node11);
foreach (string channel in search.getSearchChannels())
{
XmlElement node11a = xmlDoc.CreateElement("Channel");
XmlText node11aText = xmlDoc.CreateTextNode(channel);
node11.AppendChild(node11a);
node11a.AppendChild(node11aText);
}
//Write the search start and end dates and times
XmlElement node12 = xmlDoc.CreateElement("SearchStartDate");
XmlText node12Text = xmlDoc.CreateTextNode(search.getSearchStartDate());
node1.AppendChild(node12);
node12.AppendChild(node12Text);
XmlElement node13 = xmlDoc.CreateElement("SearchStartTime");
XmlText node13Text = xmlDoc.CreateTextNode(search.getSearchStartTime());
node1.AppendChild(node13);
node13.AppendChild(node13Text);
XmlElement node14 = xmlDoc.CreateElement("SearchEndDate");
XmlText node14Text = xmlDoc.CreateTextNode(search.getSearchEndDate());
node1.AppendChild(node14);
node14.AppendChild(node14Text);
XmlElement node15 = xmlDoc.CreateElement("SearchEndTime");
XmlText node15Text = xmlDoc.CreateTextNode(search.getSearchEndTime());
node1.AppendChild(node15);
node15.AppendChild(node15Text);
xmlDoc.Save(GetWebConfigFileName());
}
catch (Exception ex)
{
Logger.Error(ex.ToString());
}
}
public void autoSearch(ArrayList Searches)
{
Settings guideParams = Global.Settings;
Schedule scheduleHelper = Global.Schedule;
ArrayList reminders = scheduleHelper.GetReminderList();
//Set recording settings for auto-record searches
//Set pre/post padding
XmlNode pre = Global.Config.SelectSingleNode("/settings/PreShowPadding");
XmlNode post = Global.Config.SelectSingleNode("/settings/PostShowPadding");
int prePad = Convert.ToInt32(pre.InnerText);
int postPad = Convert.ToInt32(post.InnerText);
//Set the recording quality
Schedule.Quality quality = 0;
switch (Global.Settings.recordingQuality.ToLower())
{
case "high":
quality = Schedule.Quality.High;
break;
case "medium":
quality = Schedule.Quality.Medium;
break;
case "low":
quality = Schedule.Quality.Low;
break;
case "custom1":
quality = Schedule.Quality.Custom1;
break;
case "custom2":
quality = Schedule.Quality.Custom2;
break;
}
// Search for an episode listing, set the start time and the end time
DateTime startTime = DateTime.Now;
DateTime endTime = startTime.AddDays(guideParams.autoSearchDays);
IList allChannels = scheduleHelper.GetListingsForTimePeriod(startTime, endTime);
CaseInsensitiveComparer caseInsensitiveComparer = new CaseInsensitiveComparer();
int x = 0;
foreach (SavedSearch search in Searches)
{
x++;
int minLength = int.MinValue;
int maxLength = int.MaxValue;
bool checkTitle = search.getSearchTitle();
bool checkDesc = search.getSearchDescription();
bool checkSubtitle = search.getSearchSubTitle();
string searchFor = search.getSearchPhrase();
ArrayList channels = search.getSearchChannels();
ArrayList selectedGenre = search.getSearchGenres();
if ((search.getSearchLengthMin() != null) && (search.getSearchLengthMin().Length > 0)) minLength = int.Parse(search.getSearchLengthMin());
if ((search.getSearchLengthMax() != null) && (search.getSearchLengthMax().Length > 0)) maxLength = int.Parse(search.getSearchLengthMax());
DateTime savedStartDate = DateTime.Now;
DateTime savedStartTime = DateTime.Now;
DateTime savedEndDate = DateTime.Now;
DateTime savedEndTime = DateTime.Now;
int parmStartDateSum = 0;
int parmEndDateSum = 0;
bool defaultStartDateTime = false;
bool defaultEndDateTime = false;
bool validStartDate = false;
bool validStartTime = false;
bool validEndDate = false;
bool validEndTime = false;
SavedSearchUtils searchutil = new SavedSearchUtils();
//To clean up the mess I made with storing funky dates when I added a time and date parm we need to check to see if the date and time
//as a pair are a default value (meaning no date and time was entered) as well as individual defaults. To correct this moving forward I
//added a search version and can now update the search with correct default values as needed by simply resaving the search after corrections
//or updates are applied here.
//
//1/1/0001 and 12:00 a.m. = default date & time that needs to be removed and set to nulls
//
//Search version checking is done here in auto-search as well as in the search and search2 pages.
if (search.getSearchStartDate() == "1/1/0001" && search.getSearchStartTime() == "12:00 AM")
{
defaultStartDateTime = true;
search.setSearchStartDate(null);
search.setSearchStartTime(null);
}
if (search.getSearchStartDate() == "1/1/0001")
{
search.setSearchStartDate(null);
}
if (search.getSearchEndDate() == "1/1/0001" && search.getSearchEndTime() == "12:00 AM")
{
defaultEndDateTime = true;
search.setSearchEndDate(null);
search.setSearchEndTime(null);
}
if (search.getSearchEndDate() == "1/1/0001")
{
search.setSearchEndDate(null);
}
if (search.getSearchStartDate() != null && search.getSearchStartDate() != "" && search.getSearchStartDate() != "1/1/0001")
{
savedStartDate = searchutil.toDate(search.getSearchStartDate());
parmStartDateSum = savedStartDate.Month + savedStartDate.Day + savedStartDate.Year;
validStartDate = true;
}
if (search.getSearchStartTime() != null && search.getSearchStartTime() != "" && !defaultStartDateTime)
{
savedStartTime = searchutil.toDate(search.getSearchStartTime());
validStartTime = true;
}
if (search.getSearchEndDate() != null && search.getSearchEndDate() != "" && search.getSearchEndDate() != "1/1/0001")
{
savedEndDate = searchutil.toDate(search.getSearchEndDate());
parmEndDateSum = savedEndDate.Month + savedEndDate.Day + savedEndDate.Year;
validEndDate = true;
}
if (search.getSearchEndTime() != null && search.getSearchEndTime() != "" && !defaultEndDateTime)
{
savedEndTime = searchutil.toDate(search.getSearchEndTime());
validEndTime = true;
}
if (search.getSearchVersion() != guideParams.CurrentSearchVersion)
{
search.setSearchVersion(guideParams.CurrentSearchVersion);
string name = search.getSearchName();
searchutil.deleteSearch(name);
searchutil.writeSearch(search);
}
foreach (Channel channel in allChannels)
{
foreach (Programme program in channel.getProgrammeList())
{
if (searchFor != null)
{
if (!search.isCaseSensitiveSearch())
{
searchFor = searchFor.ToUpper();
}
}
bool showProgram = !checkTitle && !checkDesc && !checkSubtitle;
if (!search.isCaseSensitiveSearch())
{
if (checkTitle) showProgram |= program.getTitle().ToUpper().IndexOf(searchFor) > -1;
if (checkDesc) showProgram |= program.getDescription().ToUpper().IndexOf(searchFor) > -1;
if (checkSubtitle) showProgram |= program.getSubTitle().ToUpper().IndexOf(searchFor) > -1;
}
else
{
if (checkTitle) showProgram |= program.getTitle().IndexOf(searchFor) > -1;
if (checkDesc) showProgram |= program.getDescription().IndexOf(searchFor) > -1;
if (checkSubtitle) showProgram |= program.getSubTitle().IndexOf(searchFor) > -1;
}
double length = (program.getEndTime() - program.getStartTime()).TotalMinutes;
showProgram &= (length >= minLength) && (length <= maxLength);
int pgmStartDateSum = program.getStartTime().Month + program.getStartTime().Day + program.getStartTime().Year;
int pgmEndDateSum = program.getEndTime().Month + program.getEndTime().Day + program.getEndTime().Year;
//Date processing logic to compare programmes that have already matched a entered search parameter
//StartDate, EndDate, StartTime and EndTime will be null if they were not entered
if (showProgram)
{
//Check to see if the passed in start date is a dummy date
if (showProgram && validStartDate)
{
if (pgmStartDateSum < parmStartDateSum)
{
showProgram = false;
}
}
//Check to see if the passed in start time is a dummy time
if (showProgram && validStartTime)
{
int Cmpr =
String.Compare(program.getStartTime().ToString("HH:mm"), savedStartTime.ToString("HH:mm"));
if (Cmpr < 0)
{
showProgram = false;
}
}
//Check to see if the passed in end date is a dummy date
if (showProgram && validEndDate)
{
if (pgmEndDateSum > parmEndDateSum)
{
showProgram = false;
}
}
//Check to see if the passed in end time is a dummy time
if (showProgram && validEndTime)
{
int Cmpr =
String.Compare(program.getEndTime().ToString("HH:mm"), savedEndTime.ToString("HH:mm"));
if (Cmpr > 0)
{
showProgram = false;
}
}
}
if (showProgram && (selectedGenre != null) && (selectedGenre.Count > 0))
{
if (program.getGenreList().Count > 0)
{
ArrayList showGenres = new ArrayList(program.getGenreList());
showGenres.Sort();
foreach (string genre in selectedGenre)
{
int idx = showGenres.BinarySearch(genre, caseInsensitiveComparer);
if (idx > -1)
{
showProgram = true;
break;
}
showProgram = false;
}
}
else
{
showProgram = false;
}
}
if (channels.Count > 0)
showProgram &= channels.Contains(channel.channelNumber.ToString());
if (showProgram)
{
if (guideParams.autoShowRecord && search.isAutoRecordSearch())
{
IDictionary knownRecordings = scheduleHelper.LoadKnownRecordings();
if (!knownRecordings.Contains(program.getOID()))
{
Schedule myschedule = Global.Schedule;
bool scheduleReturn = myschedule.ScheduleOnce(program, quality, prePad, postPad);
scheduleHelper.RemoveReminder(program);
}
}
else
{
if (guideParams.autoShowSearch && search.isAutoShowSearch())
{
if (!reminders.Contains(program))
{
scheduleHelper.CreateReminder(program);
}
}
}
}
}
}
}
}
private string webConfigFileName;
private string GetWebConfigFileName()
{
if (webConfigFileName == null)
{
webConfigFileName = Path.Combine(GetInstallDir(), "web-saved-searches.xml");
}
return webConfigFileName;
}
public string GetInstallDir()
{
// determine install location
string installDirectory = @"c:\program files\devnz\gbpvr\";
try
{
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\devnz\"))
{
string temp = (string)key.GetValue("GBPVR InstallDir");
if (temp != null)
{
installDirectory = temp;
}
}
}
catch (Exception ex)
{
Logger.Error("Error reading install location from registry: " + ex.ToString());
}
return installDirectory;
}
}
#endregion
}